1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.webphotos.netbeans;
21
22 import java.awt.event.MouseEvent;
23 import java.io.Serializable;
24 import java.util.logging.Logger;
25 import org.openide.util.ImageUtilities;
26 import org.openide.util.NbBundle;
27 import org.openide.windows.TopComponent;
28 import org.openide.windows.WindowManager;
29
30
31
32
33 final class WebPhotosFormTopComponent extends TopComponent {
34
35 private static WebPhotosFormTopComponent instance;
36
37 static final String ICON_PATH = "net/sf/webphotos/netbeans/frame.png";
38 private static final String PREFERRED_ID = "WebPhotosFormTopComponent";
39
40 private WebPhotosFormTopComponent() {
41 initComponents();
42 setName(NbBundle.getMessage(WebPhotosFormTopComponent.class, "CTL_WebPhotosFormTopComponent"));
43 setToolTipText(NbBundle.getMessage(WebPhotosFormTopComponent.class, "HINT_WebPhotosFormTopComponent"));
44 setIcon(ImageUtilities.loadImage(ICON_PATH, true));
45
46 }
47
48 public void tbFotosPopupCalled(MouseEvent evt) {
49 if (tbFotos.getSelectedRowCount() <= 1) {
50 int selecao = tbFotos.rowAtPoint(evt.getPoint());
51 tbFotos.setRowSelectionInterval(selecao, selecao);
52 }
53 if (evt.isPopupTrigger()) {
54
55 }
56 }
57
58
59
60
61
62
63
64 private void initComponents() {
65 java.awt.GridBagConstraints gridBagConstraints;
66
67 painelInfoAlbum = new javax.swing.JPanel();
68 lblAlbum = new javax.swing.JLabel();
69 txtTitulo = new javax.swing.JTextField();
70 lblCategoria = new javax.swing.JLabel();
71 lstCategoriasAlbum = new javax.swing.JComboBox();
72 lblData = new javax.swing.JLabel();
73 txtData = new javax.swing.JFormattedTextField();
74 lblDescricao = new javax.swing.JLabel();
75 scrDescricao = new javax.swing.JScrollPane();
76 txtDescricao = new javax.swing.JTextArea();
77 scrFotos = new javax.swing.JScrollPane();
78 tbFotos = new javax.swing.JTable();
79
80 setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
81 setLayout(new java.awt.BorderLayout());
82
83 painelInfoAlbum.setMinimumSize(new java.awt.Dimension(500, 250));
84 painelInfoAlbum.setPreferredSize(new java.awt.Dimension(500, 300));
85 painelInfoAlbum.setLayout(new java.awt.GridBagLayout());
86
87 org.openide.awt.Mnemonics.setLocalizedText(lblAlbum, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblAlbum.text"));
88 gridBagConstraints = new java.awt.GridBagConstraints();
89 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
90 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
91 painelInfoAlbum.add(lblAlbum, gridBagConstraints);
92
93 txtTitulo.setPreferredSize(new java.awt.Dimension(477, 22));
94 gridBagConstraints = new java.awt.GridBagConstraints();
95 gridBagConstraints.gridx = 1;
96 gridBagConstraints.gridy = 0;
97 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
98 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
99 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
100 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
101 painelInfoAlbum.add(txtTitulo, gridBagConstraints);
102
103 org.openide.awt.Mnemonics.setLocalizedText(lblCategoria, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblCategoria.text"));
104 gridBagConstraints = new java.awt.GridBagConstraints();
105 gridBagConstraints.gridx = 0;
106 gridBagConstraints.gridy = 1;
107 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
108 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
109 painelInfoAlbum.add(lblCategoria, gridBagConstraints);
110
111 lstCategoriasAlbum.setModel(
112 gridBagConstraints = new java.awt.GridBagConstraints();
113 gridBagConstraints.gridx = 1;
114 gridBagConstraints.gridy = 1;
115 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
117 gridBagConstraints.weightx = 5.0;
118 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
119 painelInfoAlbum.add(lstCategoriasAlbum, gridBagConstraints);
120
121 org.openide.awt.Mnemonics.setLocalizedText(lblData, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblData.text"));
122 gridBagConstraints = new java.awt.GridBagConstraints();
123 gridBagConstraints.gridx = 2;
124 gridBagConstraints.gridy = 1;
125 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
126 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
127 painelInfoAlbum.add(lblData, gridBagConstraints);
128
129 txtData.setMinimumSize(new java.awt.Dimension(11, 22));
130 txtData.setPreferredSize(new java.awt.Dimension(72, 22));
131 gridBagConstraints = new java.awt.GridBagConstraints();
132 gridBagConstraints.gridx = 3;
133 gridBagConstraints.gridy = 1;
134 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
135 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
136 gridBagConstraints.weightx = 1.0;
137 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
138 painelInfoAlbum.add(txtData, gridBagConstraints);
139
140 org.openide.awt.Mnemonics.setLocalizedText(lblDescricao, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblDescricao.text"));
141 gridBagConstraints = new java.awt.GridBagConstraints();
142 gridBagConstraints.gridx = 0;
143 gridBagConstraints.gridy = 2;
144 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
145 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
146 painelInfoAlbum.add(lblDescricao, gridBagConstraints);
147
148 scrDescricao.setAutoscrolls(true);
149
150 txtDescricao.setLineWrap(true);
151 txtDescricao.setWrapStyleWord(true);
152 scrDescricao.setViewportView(txtDescricao);
153
154 gridBagConstraints = new java.awt.GridBagConstraints();
155 gridBagConstraints.gridx = 1;
156 gridBagConstraints.gridy = 2;
157 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
158 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
159 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
160 gridBagConstraints.weighty = 5.0;
161 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
162 painelInfoAlbum.add(scrDescricao, gridBagConstraints);
163
164 tbFotos.setToolTipText(org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.tbFotos.toolTipText"));
165 tbFotos.addMouseListener(new java.awt.event.MouseAdapter() {
166 public void mousePressed(java.awt.event.MouseEvent evt) {
167 tbFotosMousePressed(evt);
168 }
169 public void mouseReleased(java.awt.event.MouseEvent evt) {
170 tbFotosMouseReleased(evt);
171 }
172 });
173 scrFotos.setViewportView(tbFotos);
174
175 gridBagConstraints = new java.awt.GridBagConstraints();
176 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
177 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
178 gridBagConstraints.weighty = 10.0;
179 gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
180 painelInfoAlbum.add(scrFotos, gridBagConstraints);
181
182 add(painelInfoAlbum, java.awt.BorderLayout.CENTER);
183 }
184
185 private void tbFotosMousePressed(java.awt.event.MouseEvent evt) {
186 tbFotosPopupCalled(evt);
187 }
188
189 private void tbFotosMouseReleased(java.awt.event.MouseEvent evt) {
190 tbFotosPopupCalled(evt);
191 }
192
193 private javax.swing.JLabel lblAlbum;
194 private javax.swing.JLabel lblCategoria;
195 private javax.swing.JLabel lblData;
196 private javax.swing.JLabel lblDescricao;
197 private javax.swing.JComboBox lstCategoriasAlbum;
198 private javax.swing.JPanel painelInfoAlbum;
199 private javax.swing.JScrollPane scrDescricao;
200 private javax.swing.JScrollPane scrFotos;
201 private javax.swing.JTable tbFotos;
202 private javax.swing.JFormattedTextField txtData;
203 private javax.swing.JTextArea txtDescricao;
204 private javax.swing.JTextField txtTitulo;
205
206
207
208
209
210
211
212 public static synchronized WebPhotosFormTopComponent getDefault() {
213 if (instance == null) {
214 instance = new WebPhotosFormTopComponent();
215 }
216 return instance;
217 }
218
219
220
221
222 public static synchronized WebPhotosFormTopComponent findInstance() {
223 TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
224 if (win == null) {
225 Logger.getLogger(WebPhotosFormTopComponent.class.getName()).warning(
226 "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
227 return getDefault();
228 }
229 if (win instanceof WebPhotosFormTopComponent) {
230 return (WebPhotosFormTopComponent) win;
231 }
232 Logger.getLogger(WebPhotosFormTopComponent.class.getName()).warning(
233 "There seem to be multiple components with the '" + PREFERRED_ID +
234 "' ID. That is a potential source of errors and unexpected behavior.");
235 return getDefault();
236 }
237
238 @Override
239 public int getPersistenceType() {
240 return TopComponent.PERSISTENCE_ALWAYS;
241 }
242
243 @Override
244 public void componentOpened() {
245
246 }
247
248 @Override
249 public void componentClosed() {
250
251 }
252
253
254 @Override
255 public Object writeReplace() {
256 return new ResolvableHelper();
257 }
258
259 @Override
260 protected String preferredID() {
261 return PREFERRED_ID;
262 }
263
264 final static class ResolvableHelper implements Serializable {
265
266 private static final long serialVersionUID = 1L;
267
268 public Object readResolve() {
269 return WebPhotosFormTopComponent.getDefault();
270 }
271 }
272 }